/*
 * trace.h
 *
 *  Created on: Apr 2, 2009
 *      Author: toc
 */

#ifndef TRACE_H_
#define TRACE_H_

#include <vector>;

#include "time.h"

using namespace std;

class Trace_item
{
public:
  Trace_item();
  virtual ~Trace_item();

  void set_values(vector<double> values);

  void set_value(int n, double value);

  void set_time(Time time);

  Time get_time(void);

  double get_value(int n);

  void drop_value(int n);

  int get_dimension(void);

private:
  Time _time;
  vector<double> _values;
};

class Trace
{
public:
  Trace();
  virtual ~Trace();

  double get_value(int id, Time time);
  Time start_time();
  Time end_time();

  void add_value(int id, Time time, double value);
  void add_values(Time time, vector<double> values);
  void add_item(Trace_item *item);

  void set_source(int id, float *);

  void set_ids(vector<int> ids);
  void set_id(int n, int id);

  void update(Time time);

  void set_dimension(int dimension);
  int get_dimension(void);

  void drop_id(int id);
  void drop_ids(vector<int> ids);

  bool contains(Time time);

  void trim_beginning(Time time);
  void trim_end(Time time);

  Trace split(Time time);
  Trace split(Time time1, Time time2);

  int size();

  void load(string filename);
  void save(string filename);

private:
  vector<Trace_item *> _items; // values at specific times
  vector<float *> _sources; // where to take values from in update
  vector<int> _dimension_ids; // each dimension has an ID to link it to an input/model output
  int _dimension; // number of values in trace items
  Time _start_time;
  Time _end_time;

  int id2index(int id);
  double get_value_for_index(int index, Time time);
};

#endif /* TRACE_H_ */
